import machine
from machine import Pin,pwm, ADC,I2C
import time
import network
import _thread
from i2c_lcd import I2cLcd
import socket
import utime
lcd_led=Pin(15,Pin.OUT)#lcd屏幕背光
lcd_led.value(1)
i2c = I2C(0, scl=Pin(16), sda=Pin(4), freq=100000)
lcd = I2cLcd(i2c, 0x27, 4, 20)  # 4行20列
lcd.putstr("READY!")
led_g=Pin(2,Pin.OUT)
led_r=Pin(0,Pin.OUT)
led_g.value(1)
led_r.value(0)
lcd.clear()
wifi_name="Rion"
wifi_pass="8191031520"
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
lcd.putstr("Connecting to "+wifi_name)
wlan.connect(wifi_name, wifi_pass)
if wlan.isconnected():
    lcd.clear()
    lcd.putstr("Connected!")
    lcd.putstr("\nIP: "+wlan.ifconfig()[0])
else:
    lcd.clear()
    lcd.putstr("Connection failed!")

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 80))
s.listen(5)
print("Web server started on port 80")
#网络前端稍后完善
def get_time():
    time_new=utime.localtime.localtime()
    return time_new
file=open('data.csv','w')
file.write('start time',get_time(),'wifi:',wlan.ifconfig())
#日志文件






